#-*-  coding:utf-8 -*-

from selenium import webdriver
import time

#要想调用键盘按键操作需要引入keys包
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options

from selenium.webdriver import Firefox

#
options = Options()
options.add_argument('-headless')  # 无头参数
driver = Firefox(executable_path=r'D:\geckodriver-v0.21.0-win64\geckodriver.exe', firefox_options=options)  # 配了环境变量第一个参数就可以省了，不然传绝对路径


driver.set_window_size(1366, 768)

driver.get("http://www.baidu.com/")

#获取页面名为wraper的id标签的文本内容
data = driver.find_element_by_id('wrapper').text

#打印数据内容
print(data)

print(driver.title)

#打印网页渲染后的源代码
#print(driver.page_source)

#获取当前页面Cookie
#print(driver.get_cookies())

#ctrl+a全选输入框内容
driver.find_element_by_id('kw').send_keys(Keys.CONTROL, 'a')
#ctrl+x剪切输入框内容
driver.find_element_by_id('kw').send_keys(Keys.CONTROL, 'x')

#输入框重新输入内容
driver.find_element_by_id('kw').send_keys('itcast')

#模拟Enter回车键
driver.find_element_by_id('su').send_keys(Keys.RETURN)
time.sleep(5)

#清空输入框内容
driver.find_element_by_id('kw').clear()

#生成页面快照
driver.save_screenshot('itcast.png')

#获取当前url
print(driver.current_url)

driver.quit()